package contacts;

import java.io.IOException;
import java.net.IDN;

import tools.OptionReader;

public class Person {

	/**
	 * Member Section
	 */

	private int darstellung = 1;
	

	private OptionReader or;

	private String name = "";
	private String vorname = "";
	private String adresse = "";
	private String street = "";
	private String zip = "";
	private String city = "";
	private String email = "";
	private String birthday;
	private String telefonhome = "";
	private String telefonarbeit = "";
	private String fax = "";
	private String handynummer = "";
	private String fullname = vorname + " " + name;
	private String UserID;
	
	public Person(String name, String vorname,  String street,
			String zip, String city, String email, String birthday,
			String telefonhome, String telefonarbeit, String fax,
			String handynummer, String userID) {
		this.name = name;
		this.vorname = vorname;
		this.street = street;
		this.zip = zip;
		this.city = city;
		this.email = email;
		this.birthday = birthday;
		this.telefonhome = telefonhome;
		this.telefonarbeit = telefonarbeit;
		this.fax = fax;
		this.handynummer = handynummer;
		UserID = userID;
	}
	
	// Getter & Setter
	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getUserID() {
		return UserID;
	}

	public void setUserID(String userID) {
		UserID = userID;
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getVorname() {
		return vorname;
	}

	public void setVorname(String vorname) {
		this.vorname = vorname;
	}

	public String getAdresse() {
		return adresse;
	}

	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getTelefonhome() {
		return telefonhome;
	}

	public void setTelefonhome(String telefonhome) {
		this.telefonhome = telefonhome;
	}

	public String getTelefonarbeit() {
		return telefonarbeit;
	}

	public void setTelefonarbeit(String telefonarbeit) {
		this.telefonarbeit = telefonarbeit;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getHandynummer() {
		return handynummer;
	}

	public void setHandynummer(String handynummer) {
		this.handynummer = handynummer;
	}

	/**
	 * Konstruktor
	 * 
	 * @param name
	 *            Name der Person
	 * @param vorname
	 *            Vorname der Person
	 */
	public Person(String name, String vorname) {
		// init(name, vorname);
		this.name = name;
		this.vorname = vorname;

		or = new OptionReader();
		try {
			or.getOpionsFromFile();
		} catch (IOException e2) {

			e2.printStackTrace();
		}

		darstellung = Integer.parseInt(or.getConOpt2());

	}

	/**
	 * Konstruktor
	 * 
	 * @param name
	 *            Nachname der Person
	 * @param vorname
	 *            Vorname der Person
	 * @param email
	 *            Email der Person
	 * @param id
	 *            ID der Person in der Datenbank
	 */
	public Person(String name, String vorname, String email, String id) {
		// init(name, vorname);
		this.name = name;
		this.vorname = vorname;
		this.email = email;
		this.UserID = id;

		or = new OptionReader();
		try {
			or.getOpionsFromFile();
		} catch (IOException e2) {

			e2.printStackTrace();
		}

		darstellung = Integer.parseInt(or.getConOpt2());

	}

	/**
	 * Funktion ersetzt Funktion des Standartkonstruktors
	 * 
	 * @param namex
	 *            Nachname der uebergeben wird
	 * @param vornamex
	 *            Vorname der uebergeben wird
	 */

	/**
	 * Funktion gibt die Daten einer Person als String zurueck
	 */
	public String toString() {
		String s = "";

		if (adresse == "" && email == "") {

			if (darstellung == 0) {
				s = s + getVorname() + " " + name;
			}
			if (darstellung == 1) {
				s = s + name + ", " + getVorname();
			}

		} else if (adresse == "") {
			s = s + getVorname() + " " + name + "\n" + adresse + "Email: "
					+ email + "\n" + "Telefon: " + telefonhome + "\n"
					+ "Arbeit: " + telefonarbeit + "\n" + "Mobil: "
					+ handynummer + "\n" + "Fax: " + fax + "\n"
					+ "Geburtsdatum: " + birthday;
		} else {
			s = s + getVorname() + " " + name + "\n" + adresse + "\n"
					+ "Email: " + email + "\n" + "Telefon: " + telefonhome
					+ "\n" + "Arbeit: " + telefonarbeit + "\n" + "Mobil: "
					+ handynummer + "\n" + "Fax: " + fax + "\n"
					+ "Geburtsdatum: " + birthday;
		}

		return s;

	}

	/**
	 * Gibt Email Adresse als ACE String und macht eine Adresse mit Umlauten
	 * international kompatibel
	 * 
	 * @return ACE String der Email Adresse der Person
	 */
	public String mailAsAce() {

		String s = IDN.toASCII(getEmail());

		return s;
	}

}
